package com.frinder.robot.strategy.task.distribute;

import com.frinder.base.strategy.BaseStrategy;
import com.frinder.robot.handler.RobotTaskActor.ReceiveTaskPayload;
import com.frinder.robot.handler.task.RobotTask;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Map;
import java.util.Optional;

import static com.frinder.robot.strategy.task.distribute.DistributeTaskToRobotPayload.Type.PRIORITY;

/**
 * @ClassName DistributeTaskToRobotBaseStrategy
 * @Description 分派任务策略基类
 * @Author frinder
 * @Date 2019/10/19 14:28
 * @Verion 1.0
 */
@Slf4j
public class DistributeTaskToRobotBaseStrategy extends BaseStrategy<DistributeTaskToRobotPayload> {

    @Autowired
    protected Map<String, RobotTask> RobotTasks;

    /**
     * 下发任务
     *
     * @param payload
     * @param task
     */
    protected void distribute(DistributeTaskToRobotPayload payload, Optional<RobotTask> task) {
        log.info("{} Payload: {}", PRIORITY, payload);
        ReceiveTaskPayload receiveTaskPayload = ReceiveTaskPayload.builder().build();
        task.ifPresent(o -> receiveTaskPayload.setTask(o));
        payload.getReceiver().tell(receiveTaskPayload, payload.getSender());
    }

}
